package com.xuecheng.auth.controller;

import com.xuecheng.ucenter.model.po.XcUser;
import com.xuecheng.ucenter.service.SendMailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.concurrent.TimeUnit;

@Slf4j
@Controller
public class MailController {
    @Autowired
    SendMailService sendMailService;
    @Autowired
    RedisTemplate redisTemplate;
    //发送验证码
    @RequestMapping("/sendMsg")
    public boolean code(String email){
        String userEmail=email;
        if (userEmail!=null){
            String mailCode = sendMailService.sendMail(userEmail);
            log.info("验证码是"+mailCode);
            //保存生成的验证码
            redisTemplate.opsForValue().set("mailCheckCode:"+userEmail,mailCode,5, TimeUnit.MINUTES);
            return true;
        }
        return false;
    }

}
